import * as actionTypes from './constants'
import {getTopBanner,getHotRecommend,getNewAlbum,getTopList,getArtistList} from '@/services/recommend'

const changeTopBannerAction = (res) =>({
    type: actionTypes.CHANGE_TOP_BANNERS,
    topBanners: res.banners
})

const changeHotRecommendAction = (res) =>({
    type:actionTypes.CHANGE_HOT_RECOMMEND,
    hotRecommends:res.result
})
const changeNewAlubmAction = (res) =>({
    type:actionTypes.CHANGE_NEW_ALBUM,
    newAlbums:res.albums
})

const changeUpRankingAction = (res) =>({
    type:actionTypes.CHANGE_UP_RANKING,
    upRankings:res.playlist
})
const changeNewRankingAction = (res) =>({
    type:actionTypes.CHANGE_NEW_RANKING,
    newRankings:res.playlist
})
const changeOriginRankingAction = (res) =>({
    type:actionTypes.CHANGE_ORIGIN_RANKING,
    originRankings:res.playlist
})

const changeSettleSingerAction = (res) =>({
    type:actionTypes.CHANGE_SETTLE_SINGER,
    settleSingers:res.artists
})

export const getTopBannerAction = ()=>{
    return dispatch=>{
        getTopBanner().then(res=>{
            dispatch(changeTopBannerAction(res))
        })
    }
}
export const getHotRecommendAction = (limit)=>{
    return dispatch=>{
        getHotRecommend(limit).then(res=>{
            dispatch(changeHotRecommendAction(res));
            // console.log(res);
        })
    }
}
export const getNewAlbumAction = (limit)=>{
    return dispatch=>{
        getNewAlbum(limit).then(res=>{
            dispatch(changeNewAlubmAction(res));
            // console.log(res);
        })
    }
}

export const getTopListAction = (idx)=>{
    return dispatch=>{
        getTopList(idx).then(res=>{
            // dispatch()
            switch(idx){
                case 0:
                    dispatch(changeUpRankingAction(res));
                    break;
                case 2:
                    dispatch(changeNewRankingAction(res));
                    break;
                case 3:
                    dispatch(changeOriginRankingAction(res));
                    break;
                default:
            }
        })
    }
}

export const getSettleSingerAction = () =>{
    return dispatch =>{
        getArtistList(5,5001).then(res=>{
            dispatch(changeSettleSingerAction(res))
            // console.log(res);
        })
    }
}

// dispatch(getTopBannerAction())
